package com.kky.pp.activity.home

import android.Manifest
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Message
import android.provider.Settings
import android.util.Log
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible
import androidx.fragment.app.FragmentActivity
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.custom.base.config.BaseConfig
import com.custom.base.entity.OkHttpBodyEntity
import com.custom.base.entity.PageModel
import com.custom.base.http.OkHttpFromBoy
import com.custom.base.http.OkHttpManager
import com.custom.base.http.SDOkHttpResoutCallBack
import com.custom.base.mvp.BasePresenterImpl
import com.custom.base.util.SystemUtil
import com.google.gson.JsonObject
import com.kky.pp.BuildConfig
import com.kky.pp.common.Constant
import com.kky.pp.R
import com.kky.pp.popup.NotificationRequestPopup
import com.kky.pp.popup.UpdateApkPopup
import com.kky.pp.dot.DotLogEventName
import com.kky.pp.dot.DotLogUtil
import com.kky.pp.entity.ConfigsEntity
import com.kky.pp.entity.ConfigsPrivateEntity
import com.kky.pp.entity.ConversationListEntity
import com.kky.pp.entity.IMMatchEntity
import com.kky.pp.entity.UpdateApkEntity
import com.kky.pp.entity.UserBaseInfoEntity
import com.kky.pp.entity.WhoLikeMeEntity
import com.kky.pp.socket.event.EventFactory
import com.kky.pp.socket.event.UnifyEvent
import com.kky.pp.socket.netty.NettyClient
import com.kky.pp.util.CollectionUtils
import com.kky.pp.util.HandlerUtils
import com.kky.pp.util.PermissionUtils
import com.kky.pp.util.SystemUtils
import com.custom.base.base.SDEventManager
import io.rong.imkit.RongIM
import io.rong.imkit.SpName
import io.rong.imkit.config.BaseDataProcessor
import io.rong.imkit.config.RongConfigCenter
import io.rong.imkit.conversationlist.ConversationListFragment
import io.rong.imkit.event.EnumEventTag
import io.rong.imkit.manager.UnReadMessageManager
import io.rong.imkit.userinfo.RongUserInfoManager
import io.rong.imkit.userinfo.UserDataProvider
import io.rong.imkit.utils.JsonUtils
import io.rong.imlib.RongIMClient
import io.rong.imlib.model.Conversation
import io.rong.imlib.model.UserInfo
import org.json.JSONException
import org.json.JSONObject
import razerdp.basepopup.BasePopupWindow
import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.Executors


/**
 * 作者：
 * 时间：
 * 描述：主页
 */
class HomePresenter : BasePresenterImpl<HomeContract.View>(), HomeContract.Presenter,
    HandlerUtils.OnReceiveMessageListener {

    private val Permission_Request = 10001
    private var loRingTheBell: ImageView? = null
    private var notificationContainer: ConstraintLayout? = null
    private var imgNotificationClose: ImageView? = null
    private var inflate: View? = null
    private var index = 0
    private var serverCount = 0
    private var matchArrayList: ArrayList<IMMatchEntity.Data> = arrayListOf()
    var handel = HandlerUtils.HandlerHolder(this)
    private var serverUserCode: String = ""
    fun onCreate(savedInstanceState: Bundle?, homeActivity: HomeActivity) {
        mView?.apply {
            //设置用户头像/昵称
            RongUserInfoManager.getInstance()
                .setUserInfoProvider(object : UserDataProvider.UserInfoProvider {
                    override fun getUserInfo(userId: String?): UserInfo? {
                        var newUserInfo: UserInfo? = null
                        userId?.let {
                            if (newUserInfo == null) {
                                OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
                                    override fun addBody(requestBody: OkHttpBodyEntity) {
                                        requestBody.setPost(Constant.user_user_base_url)
                                        requestBody.add("userCode", userId)
                                    }
                                }, object : SDOkHttpResoutCallBack<UserBaseInfoEntity>(false) {
                                    override fun onSuccess(entity: UserBaseInfoEntity) {
                                        newUserInfo = UserInfo(
                                            entity.data.userCode,
                                            entity.data.nickName,
                                            Uri.parse(entity.data.avatarUrl)
                                        )
                                        RongUserInfoManager.getInstance()
                                            .refreshUserInfoCache(newUserInfo)
                                    }
                                })
                            }
                        }
                        return newUserInfo
                    }
                }, true)

            uploadVersionInfo()
            //融云会话列表头部、空数据添加
            IMConfig()
            getWLMData()

            //私密开关
            ppSwitch()


            checkUpdate()

            goIndex(index)

            OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
                override fun addBody(requestBody: OkHttpBodyEntity) {
                    requestBody.setPost(Constant.user_conversation_list_url)
                }
            }, object : SDOkHttpResoutCallBack<ConversationListEntity>(false) {
                override fun onSuccess(entity: ConversationListEntity) {
                    if (entity.data != null) {
                        if (CollectionUtils.isNotEmpty(entity.data)) {
                            repeat(entity.data.size) {
                                BaseConfig.getInstance.setInt(
                                    SpName.conversationFlashList + entity.data[it].userCodeFriend,
                                    entity.data[it].flashchatFlag
                                )
                                BaseConfig.getInstance.setInt(
                                    SpName.conversationList + entity.data[it].userCodeFriend,
                                    entity.data[it].onlineStatus
                                )
                            }
                        }
                    }
                }
            })
        }

        startSocket(if (BuildConfig.DEBUG) "ws://120.26.196.82:9002/ws" else "ws://165.154.163.79:9002/ws")
        handel.sendEmptyMessage(1)
        loadMeBottomAvatar()
    }

    private fun ppSwitch() {
        OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
            override fun addBody(requestBody: OkHttpBodyEntity) {
                requestBody.setPost(Constant.user_config_url)
                requestBody.add("code", 3)
            }
        }, object : SDOkHttpResoutCallBack<ConfigsPrivateEntity>(false) {
            override fun onSuccess(entity: ConfigsPrivateEntity) {
                BaseConfig.getInstance.setBoolean(
                    SpName.privatePhotoShowUnableFlag,
                    entity.data.photoShowUnableFlag
                )
            }
        })
    }

    /**
     * 上传设备信息
     */
    private fun uploadVersionInfo() {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
//            PermissionUtil().requestPermissions(listOf(
//                Manifest.permission.ACCESS_FINE_LOCATION,
//                Manifest.permission.ACCESS_COARSE_LOCATION,
//            ), 1001, object : PermissionUtil.OnIsOverMarshmallow {
//                override fun noIsOverMarshmallow() {
//                    uploadGps()
//                }
//            })
//        } else {
        if (!PermissionUtils.lacksPermission(
                mActivity,
                Manifest.permission.ACCESS_FINE_LOCATION
            ) || !PermissionUtils.lacksPermission(
                mActivity,
                Manifest.permission.ACCESS_COARSE_LOCATION
            )
        ) {
            uploadPermission(1, 1)
            uploadGps()
        } else {
            uploadPermission(0, 1)
        }
        uploadPermission(
            if (PermissionUtils.lacksPermission(
                    mActivity,
                    Manifest.permission.POST_NOTIFICATIONS
                )
            ) 0 else 1, 2
        )

    }

    private fun uploadPermission(grantFlag: Int, type: Int) {
        OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
            override fun addBody(requestBody: OkHttpBodyEntity) {
                requestBody.setPost(Constant.user_permission_operate_url)

                requestBody.add("permissionType", type)
                requestBody.add("grantFlag", grantFlag)
            }
        }, object : SDOkHttpResoutCallBack<IMMatchEntity>(false) {
            override fun onSuccess(entity: IMMatchEntity) {

            }
        }, isShowDialog = false)
    }

    private fun uploadGps() {
        try {
            Thread {
                OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
                    override fun addBody(requestBody: OkHttpBodyEntity) {
                        requestBody.setPost(Constant.user_add_device_info_url)
                        SystemUtils.getGPS(mActivity)?.let { requestBody.add("gps", it) }

                        if (SystemUtils.isWifiEnabled(mActivity)) {
                            if (SystemUtils.getWifiList().isNotEmpty())
                                requestBody.add("wifilist", SystemUtils.getWifiList())
                        }
                        val systemInfo = JsonObject()
                        systemInfo.addProperty("brand", SystemUtil.deviceBrand)//	品牌
                        requestBody.add("systeminfo", systemInfo)
                    }
                }, object : SDOkHttpResoutCallBack<IMMatchEntity>(false) {
                    override fun onSuccess(entity: IMMatchEntity) {

                    }
                }, isShowDialog = false)
            }.start()

        } catch (e: Exception) {

        }
    }

    /**
     * 检查更新
     */
    fun checkUpdate() {
        OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
            override fun addBody(requestBody: OkHttpBodyEntity) {
                requestBody.setGet(Constant.user_apk_update_url)
                requestBody.add("versionCode", SystemUtils.getVersionCode(mActivity))
                requestBody.add("appCode", "chat01")
            }
        }, object : SDOkHttpResoutCallBack<UpdateApkEntity>(false) {
            override fun onSuccess(entity: UpdateApkEntity) {
                if (entity.data.updateFlag) {
                    val updateApkDialog = UpdateApkPopup(
                        mActivity,
                        entity.data.upGradationDesc,
                        entity.data.updateType
                    )
                    updateApkDialog.showPopupWindow()
                    updateApkDialog.onDismissListener = object :
                        BasePopupWindow.OnDismissListener() {
                        override fun onDismiss() {
                            if (entity.data.updateType == 1) {
                                RongIM.getInstance().logout()
                                mActivity.finish()
                            }
                        }

                    }
                }
            }
        }, isShowDialog = false)
    }

    /**
     * 融云配置
     */
    fun IMConfig() {
        mView?.apply {
            val conversationListFragment =
                homeTabBottomNavs.getFragment(2) as ConversationListFragment
            inflate = View.inflate(mActivity, R.layout.layout_chat_header, null)
            conversationListFragment.addHeaderView(inflate)
            val view = View.inflate(mActivity, R.layout.layout_chat_empty, null)
            var insideContainer = view.findViewById<LinearLayout>(R.id.linearChatEmptyInsideContainer)
            conversationListFragment.setEmptyView(view)
            imgNotificationClose = inflate?.findViewById(R.id.imgViewChatHeaderNotificationClose)
            notificationContainer = inflate?.findViewById(R.id.conChatHeadNotificationContainer)
            loRingTheBell = inflate?.findViewById(R.id.imgViewChatHeadLoRingTheBell)

            OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
                override fun addBody(requestBody: OkHttpBodyEntity) {
                    requestBody.setPost(Constant.user_config_url)
                    requestBody.add("code", 1)
                }
            }, object : SDOkHttpResoutCallBack<ConfigsEntity>(false) {
                override fun onSuccess(entity: ConfigsEntity) {
                    if (entity.data.isNotEmpty()) {
                        serverUserCode = entity.data[0].userCode.toString()
                        BaseConfig.getInstance.setString(SpName.serverUserCode, serverUserCode)
                        RongIMClient.getInstance().getUnreadCount(
                            Conversation.ConversationType.PRIVATE,
                            serverUserCode,
                            object : RongIMClient.ResultCallback<Int>() {
                                override fun onSuccess(childCount: Int) {
                                    serverCount = childCount
                                    Log.e("~~~", "onSuccess: " + childCount)
                                }

                                override fun onError(e: RongIMClient.ErrorCode?) {
                                }

                            })

                        RongConfigCenter.conversationListConfig()
                            .setDataProcessor(object : BaseDataProcessor<Conversation?>() {
                                override fun filtered(data: List<Conversation?>): List<Conversation?> {
                                    val newList: ArrayList<Conversation?> = arrayListOf()
                                    for (item in data) {
                                        val targetId = item?.targetId
                                        if (serverUserCode != "" && serverUserCode == targetId) {
                                            serverCount = item.unreadMessageCount
                                        } else {
                                            newList.add(item)
                                        }
                                    }
                                    //过滤后的数据
                                    return super.filtered(newList)
                                }
                            })

                        UnReadMessageManager.getInstance()
                            .addObserver(arrayOf(Conversation.ConversationType.PRIVATE),
                                object : UnReadMessageManager.IUnReadMessageObserver {
                                    override fun onCountChanged(count: Int) {
                                        val showCount = count - serverCount
                                        homeTabBottomNavs.upDataTagNum(
                                            2,
                                            if (showCount > 100) "99+" else "$showCount"
                                        )
                                    }

                                })


                        RongIM.getInstance().refreshUserInfoCache(
                            UserInfo(
                                entity.data[0].userCode,
                                entity.data[0].name,
                                Uri.parse(entity.data[0].iocn)
                            )
                        )

                    }
                }
            })


            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && PermissionUtils.lacksPermission(
                    mActivity,
                    Manifest.permission.POST_NOTIFICATIONS
                )
            ) {
                DotLogUtil.setEventName(DotLogEventName.NOTIFICATION_PAGE_IN_CHAT_LIST).commit()
            }

            notificationContainer?.visibility =
                if (PermissionUtils.lacksPermission(
                        mActivity,
                        Manifest.permission.POST_NOTIFICATIONS
                    ) && BaseConfig.getInstance.getBoolean(SpName.firstShowNotification, false)
                ) View.VISIBLE else View.GONE
            if (notificationContainer?.isVisible == true) {
                insideContainer.visibility = View.GONE
            } else {
                insideContainer.visibility = View.VISIBLE
            }
            notificationContainer?.setOnClickListener {
//                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                PermissionUtils.requestPermission(mActivity,
                    {
                        notificationContainer?.visibility = View.GONE
                        //                        HttpRequest.commonNotify(503, "502")
                        DotLogUtil.setEventName(DotLogEventName.NOTIFICATION_PAGE_GRANTED)
                            .setRemark("502").commit()
                    }, {
                        val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
                        val uri = Uri.fromParts("package", mActivity.packageName, null)
                        intent.data = uri
                        mActivity.startActivityForResult(intent, Permission_Request)
                        //                        HttpRequest.commonNotify(503, "502")
                        DotLogUtil.setEventName(DotLogEventName.NOTIFICATION_PAGE_GRANTED)
                            .setRemark("502").commit()
                    }, Manifest.permission.POST_NOTIFICATIONS
                )
//                }
            }

            imgNotificationClose?.setOnClickListener {
                notificationContainer?.visibility = View.GONE
                insideContainer.visibility = View.VISIBLE
            }

        }

    }

    fun getMatchList() {
        OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
            override fun addBody(requestBody: OkHttpBodyEntity) {
                requestBody.setPost(Constant.user_users_matched_list_url)
            }
        }, object : SDOkHttpResoutCallBack<IMMatchEntity>(false) {
            override fun onSuccess(entity: IMMatchEntity) {
                if (CollectionUtils.isNotEmpty(entity.data)) {
                    for (i in 0 until entity.data.size) {
                        Glide.with(mActivity)
                            .load(entity.data[i].avatarUrl)
                            .diskCacheStrategy(DiskCacheStrategy.ALL)
                            .preload()
                    }
//                    ivMewFriendsTitle?.visibility = View.VISIBLE
//                    imMatchList?.visibility = View.VISIBLE
//                    imgNewFriends?.visibility = View.INVISIBLE
                    matchArrayList.clear()
                    matchArrayList.addAll(entity.data)
//                    imMatchedAdapter.notifyDataSetChanged()
                } else {
//                    imMatchList?.visibility = View.GONE
//                    imgNewFriends?.visibility = View.GONE
//                    ivMewFriendsTitle?.visibility = View.GONE
                }
            }
        })
    }

    fun showNotificationDialog(nickName: String) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && PermissionUtils.lacksPermission(
                mActivity,
                Manifest.permission.POST_NOTIFICATIONS
            ) && !BaseConfig.getInstance.getBoolean(SpName.firstShowNotification + nickName, false)
        ) {
            NotificationRequestPopup(
                mActivity,
                nickName,
                object : NotificationRequestPopup.OnListener {
                    override fun onGrantedListener() {
                        notificationContainer?.visibility = View.GONE
                    }

                    override fun onDeniedListener() {
                        val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
                        val uri = Uri.fromParts("package", mActivity.packageName, null)
                        intent.data = uri
                        mActivity.startActivityForResult(intent, Permission_Request)
                    }

                }).showPopupWindow()
        }
    }

    fun setWLMLikeSize(size: Int) {
        mView?.apply {
            homeTabBottomNavs.upDataTagNum(1, "$size")
        }
    }

    override fun goIndex(index: Int) {
        mView?.apply {
            this@HomePresenter.index = index
            homeTabBottomNavs.switchFragment(mActivity as FragmentActivity, index)
        }
    }

    fun onResume() {
        if (this@HomePresenter.index == 2) {
            getMatchList()
        }
    }

    fun getIndex(): Int {
        return this.index
    }

    fun setIndex(index: Int) {
        this.index = index
        if (index == 2) {
            showNotificationDialog("")
        }
        mView?.apply {
            homeTabBottomNavs.setBg(index)
            //homeTabBottomNavs.ivMy.setBackgroundResource(if (index == 3) R.drawable.shape_me_select_bg else R.drawable.shape_me_unselect_bg)
        }
    }

    fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (requestCode == Permission_Request) {
//            notificationContainer?.visibility =
//                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && PermissionUtils.lacksPermission(
//                        mActivity,
//                        Manifest.permission.POST_NOTIFICATIONS
//                    )  && BaseConfig.getInstance.getBoolean(SpName.firstShowNotification, false)
//                ) View.VISIBLE else View.GONE
        } else {
            mView?.apply {
                homeTabBottomNavs.getFragment(index).onActivityResult(requestCode, resultCode, data)
            }
        }
    }

    var page = PageModel()


    fun getWLMData() {
        mView?.apply {
            OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
                override fun addBody(requestBody: OkHttpBodyEntity) {
                    requestBody.setPost(Constant.user_wlm_list_url)
                    requestBody.addPage(page)
                }
            }, object : SDOkHttpResoutCallBack<WhoLikeMeEntity>(false) {
                override fun onSuccess(entity: WhoLikeMeEntity) {
                    homeTabBottomNavs.upDataTagNum(1, "${entity.data.wlmNum}")
                    val bundle = Bundle()
                    bundle.putSerializable("wlmData", entity.data)
                    homeTabBottomNavs.getFragment(1).arguments = bundle
                }

                override fun onFinish() {

                }
            })
        }
    }

    fun startSocket(hostUrl: String) {
        Executors.newSingleThreadExecutor().execute {
            Log.e("NettyClient", "run: $hostUrl")
            val nettyClient: NettyClient = NettyClient.getInst()
            nettyClient.setContext(mActivity)
            nettyClient.hostUrl = hostUrl
            // 启动并初始化
            var tk = ""
            try {
                tk = BaseConfig.getInstance.getString(SpName.userCode, "")
                nettyClient.token = tk
            } catch (e: Exception) {
                Log.i("HomeFragment", "Get token exception")
            }
            if (!nettyClient.isConnectFlag) {
                nettyClient.startConnectServerAlways()
            }
        }
    }


    /**
     *
     */
    private fun getSocketInfo() {
        try {
            val queue: ConcurrentLinkedQueue<UnifyEvent> = EventFactory.getQuotesInstance()
            while (!queue.isEmpty()) {
                //从队列取出一个元素 排队的人少一个
                val poll: UnifyEvent = queue.poll()
                val body: String = poll.body
                val bizCode: String = poll.bizCode
                when {
                    "S20000".equals(bizCode, ignoreCase = true) -> {
//                        if (JsonUtils.isJSON(body)) {
//                            SDEventManager.post(body, EnumEventTag.WLM_ADD_ITEM.ordinal)
//                        }

                    }

                    "S20001".equals(bizCode, ignoreCase = true) -> {
                        if (JsonUtils.isJSON(body)) {
                            val jsonObject = JSONObject(body)
                            RongIM.getInstance().refreshUserInfoCache(
                                UserInfo(
                                    jsonObject.getString("userCode"),
                                    jsonObject.getString("nickName"),
                                    Uri.parse(jsonObject.getString("avatarUrl"))
                                )
                            )
                        }
                    }

                    "S20002".equals(bizCode, ignoreCase = true) -> {//首页在线状态
                        SDEventManager.post(body, EnumEventTag.INDEX_REFRESH_DATA_ITEM.ordinal)

                    }

                    "S20003".equals(bizCode, ignoreCase = true) -> {//WLM在线状态
                        SDEventManager.post(body, EnumEventTag.WLM_REFRESH_ITEM.ordinal)
                    }

                    "S20004".equals(bizCode, ignoreCase = true) -> {//NEW MATCH在线状态
                        if (JsonUtils.isJSON(body)) {
                            val jsonObject = JSONObject(body)
                            refreshItem(
                                jsonObject.getString("userCode"),
                                jsonObject.getInt("online")
                            )
                        }
                    }

                    "S20005".equals(bizCode, ignoreCase = true) -> {//CHAT LIST在线状态
                        if (JsonUtils.isJSON(body)) {
                            val jsonObject = JSONObject(body)
                            if (BaseConfig.getInstance.getInt(
                                    SpName.conversationList + jsonObject.getString(
                                        "userCode"
                                    ), 0
                                ) != jsonObject.getInt("online")
                            ) {
                                BaseConfig.getInstance.setInt(
                                    SpName.conversationList + jsonObject.getString(
                                        "userCode"
                                    ), jsonObject.getInt("online")
                                )
                                if (jsonObject.has("flashchatFlag")) {
                                    BaseConfig.getInstance.setInt(
                                        SpName.conversationFlashList + jsonObject.getString(
                                            "userCode"
                                        ), jsonObject.getInt("flashchatFlag")
                                    )
                                }
                                SDEventManager.post(
                                    jsonObject.getString("userCode"),
                                    EnumEventTag.CHAT_LIST_ITEM.ordinal
                                )
                            }
                        }
                    }

                    "S20006".equals(bizCode, ignoreCase = true) -> {
                        getMatchList()
                    }
                }
            }
        } catch (e: JSONException) {
            e.printStackTrace()
        }
    }

    override fun handlerMessage(msg: Message?) {
        when (msg?.what) {
            1 -> {
                getSocketInfo()
                handel.sendEmptyMessageDelayed(1, 5000)

            }
        }
    }

    fun loadMeBottomAvatar(avatarUrl: String? = null) {
        val imageUrl = if (avatarUrl.isNullOrEmpty()) {
            BaseConfig.getInstance.getString(SpName.avatarUrl, "")
        } else {
            avatarUrl
        }
        if (imageUrl.isNullOrEmpty())
            return
        mView?.apply {
            homeTabBottomNavs.setImg(imageUrl)
//            Glide.with(mActivity)
//                .load(imageUrl)
//                .apply(RequestOptions.bitmapTransform(CircleCrop()))
//                .into(homeTabBottomNavs.ivMy)
//            homeTabBottomNavs.ivMy.tag = "1"
//            val layoutParams = bottomView.ivMy.layoutParams as ConstraintLayout.LayoutParams
//            layoutParams.width = DensityUtil.dip2px(bottomView.ivMy.context,30f)
//            layoutParams.height = DensityUtil.dip2px(bottomView.ivMy.context,30f)
//            val padding = DensityUtil.dip2px(bottomView.ivMy.context,2f)
//            bottomView.ivMy.setPadding(padding,padding,padding,padding)
            BaseConfig.getInstance.setString(SpName.avatarUrl, imageUrl)
        }
    }

    fun refreshItem(userCode: String, onlineStatus: Int) {
//        imMatchedAdapter?.let {
//            var position = 0
//            for (i in 0 until imMatchedAdapter.dataList.size) {
//                if (imMatchedAdapter.dataList[i].userCodeFriend == userCode) {
//                    position=i
//                    imMatchedAdapter.dataList[i].online =onlineStatus
//                    break
//                }
//            }
//            imMatchedAdapter.notifyItemChanged(position)
//        }

    }

}